home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Oberon / examples.lha / Examples / Oberon0 / Shapes0.Mod < prev    next >
Encoding:
Text File  |  1994-06-16  |  3.6 KB  |  135 lines

  1. MODULE Shapes0;  (*HM Mar-25-92*)
  2. IMPORT OS, Viewers0;
  3.  
  4. TYPE
  5.   Shape* = POINTER TO ShapeDesc;
  6.   ShapeDesc* = RECORD (OS.ObjectDesc)
  7.     selected*: BOOLEAN; (*TRUE: shape is selected*)
  8.     next: Shape
  9.   END;
  10.   
  11.   Graphic* = POINTER TO GraphicDesc;
  12.   GraphicDesc* = RECORD
  13.     shapes*: Shape
  14.   END;
  15.   
  16.   NotifyChangeMsg* = RECORD (OS.Message) g*: Graphic END;
  17.  
  18. VAR
  19.   curShape*: ARRAY 32 OF CHAR;  (*name of current shape type*)
  20.  
  21. PROCEDURE (s: Shape) Draw* (f: Viewers0.Frame); END Draw;
  22. PROCEDURE (s: Shape) Move* (dx, dy: INTEGER); END Move;
  23. PROCEDURE (s: Shape) Copy* (): Shape; END Copy;
  24. PROCEDURE (s: Shape) SetSelection* (x, y, w, h: INTEGER); END SetSelection;
  25. PROCEDURE (s: Shape) GetBox* (VAR x, y, w, h: INTEGER); END GetBox;
  26.  
  27. PROCEDURE (s: Shape) SetBox* (x, y, w, h: INTEGER);
  28. BEGIN s.selected := FALSE;
  29. END SetBox;
  30.  
  31. PROCEDURE (s: Shape) Neutralize*;
  32. BEGIN s.selected := FALSE
  33. END Neutralize;
  34.  
  35.  
  36. PROCEDURE InitGraphic* (VAR g: Graphic);
  37. BEGIN g.shapes := NIL
  38. END InitGraphic;
  39.  
  40. PROCEDURE (g: Graphic) Insert* (s: Shape);
  41.   VAR msg: NotifyChangeMsg;
  42. BEGIN s.next := g.shapes; g.shapes := s; msg.g := g; Viewers0.Broadcast(msg)
  43. END Insert;
  44.  
  45. PROCEDURE (g: Graphic) DeleteSelected*;
  46.   VAR s, s0: Shape; msg: NotifyChangeMsg;
  47. BEGIN s := g.shapes; s0 := NIL;
  48.   WHILE s # NIL DO
  49.     IF s.selected THEN
  50.       IF s0 = NIL THEN g.shapes := s.next ELSE s0.next := s.next END
  51.     ELSE s0 := s
  52.     END;
  53.     s := s.next
  54.   END;
  55.   msg.g := g; Viewers0.Broadcast(msg)
  56. END DeleteSelected;
  57.  
  58. PROCEDURE (g: Graphic) MoveSelected* (dx, dy: INTEGER);
  59.   VAR s: Shape; msg: NotifyChangeMsg;
  60. BEGIN s := g.shapes;
  61.   WHILE s # NIL DO
  62.     IF s.selected THEN s.Move(dx, dy) END;
  63.     s := s.next
  64.   END;
  65.   msg.g := g; Viewers0.Broadcast(msg)
  66. END MoveSelected;
  67.  
  68. PROCEDURE (g: Graphic) Draw* (f: Viewers0.Frame);
  69.   VAR s: Shape;
  70. BEGIN s := g.shapes; WHILE s # NIL DO s.Draw(f); s := s.next END
  71. END Draw;
  72.  
  73. PROCEDURE (g: Graphic) Copy* (): Graphic;
  74.   VAR s, a, b: Shape; g1: Graphic;
  75. BEGIN
  76.   NEW(g1); g1.shapes := NIL;
  77.   s := g.shapes;
  78.   WHILE s # NIL DO
  79.     a := s.Copy(); a.next := NIL;
  80.     IF g1.shapes = NIL THEN g1.shapes := a ELSE b.next := a END;
  81.     b := a; s := s.next
  82.   END;
  83.   RETURN g1
  84. END Copy;
  85.  
  86. PROCEDURE (g: Graphic) Neutralize*;
  87.   VAR s: Shape; msg: NotifyChangeMsg; changed: BOOLEAN;
  88. BEGIN s := g.shapes; changed := FALSE;
  89.   WHILE s # NIL DO changed := changed OR s.selected; s.Neutralize; s := s.next
  90. END;
  91.   IF changed THEN msg.g := g; Viewers0.Broadcast(msg) END
  92. END Neutralize;
  93.  
  94. PROCEDURE (g: Graphic) SetSelection* (x, y, w, h: INTEGER);
  95.   VAR s: Shape; msg: NotifyChangeMsg;
  96. BEGIN s := g.shapes;
  97.   WHILE s # NIL DO s.SetSelection(x, y, w, h); s := s.next END;
  98.   msg.g := g; Viewers0.Broadcast(msg)
  99. END SetSelection;
  100.  
  101. PROCEDURE (g: Graphic) GetBox* (VAR x, y, w, h: INTEGER);
  102.   VAR x0, y0, w0, h0: INTEGER; s: Shape;
  103. BEGIN
  104.   x := 0; y := 0; w := 12; h := 12;
  105.   s := g.shapes;
  106.   IF s # NIL THEN s.GetBox(x, y, w, h); s := s.next END;
  107.   WHILE s # NIL DO s.GetBox(x0, y0, w0, h0);
  108.     IF x0 < x THEN INC(w, x - x0); x := x0 END;
  109.     IF y0 < y THEN INC(h, y - y0); y := y0 END;
  110.     IF x0 + w0 > x + w THEN w := x0 + w0 - x END;
  111.     IF y0 + h0 > y + h THEN h := y0 + h0 - y END;
  112.     s := s.next
  113.   END;
  114. END GetBox;
  115.  
  116. PROCEDURE (g: Graphic) Load* (VAR r: OS.Rider);
  117.   VAR s, last: Shape; x: OS.Object;
  118. BEGIN last := NIL;
  119.   REPEAT r.ReadObj(x);
  120.     IF x = NIL THEN s := NIL ELSE s := x(Shape) END;
  121.     IF last = NIL THEN g.shapes := s ELSE last.next := s END;
  122.     last := s
  123.   UNTIL x = NIL  (*terminated by a NIL shape*)
  124. END Load;
  125.  
  126. PROCEDURE (g: Graphic) Store* (VAR r: OS.Rider);
  127.   VAR s: Shape;
  128. BEGIN s := g.shapes; WHILE s # NIL DO r.WriteObj(s); s := s.next END;
  129.   r.WriteObj(NIL)
  130. END Store;
  131.  
  132.  
  133. BEGIN curShape := ""
  134. END Shapes0.
  135.